package Wust_Java_Club_Middle_Test;

import java.util.Scanner;

public class Permutation {
	static Scanner in = new Scanner(System.in);
	static int[] num;
	static int n;
	static boolean[] exist;
	
	public static void dfs(int step) {
		if(step>n) {
			for(int i=1;i<=n;i++) {
				System.out.print("    "+num[i]);
			}
			System.out.println();
		}
		
		for(int i=1;i<=n;i++) {
			if(exist[i]) continue;
			exist[i]=true;
			num[step]=i;
			dfs(step+1);
			exist[i]=false;
		}
	}
	public static void main(String[] args) {
		n = in.nextInt();
		num = new int[n+1];
		exist = new boolean[n+1];
		dfs(1);
	}
}
